package com.lyh.web.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lyh.common.annotation.Log;
import com.lyh.common.core.controller.BaseController;
import com.lyh.common.core.domain.AjaxResult;
import com.lyh.common.enums.BusinessType;
import com.lyh.system.domain.MemberRole;
import com.lyh.system.service.IMemberRoleService;
import com.lyh.common.utils.poi.ExcelUtil;
import com.lyh.common.core.page.TableDataInfo;

/**
 * 用户角色Controller
 * 
 * @author ruoyi
 * @date 2023-04-27
 */
@RestController
@RequestMapping("/app/memberRole")
public class MemberRoleController extends BaseController
{
    @Autowired
    private IMemberRoleService memberRoleService;

    /**
     * 查询用户角色列表
     */
    @PreAuthorize("@ss.hasPermi('system:role:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberRole memberRole)
    {
        startPage();
        List<MemberRole> list = memberRoleService.selectMemberRoleList(memberRole);
        return getDataTable(list);
    }

    /**
     * 导出用户角色列表
     */
    @PreAuthorize("@ss.hasPermi('system:role:export')")
    @Log(title = "用户角色", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberRole memberRole)
    {
        List<MemberRole> list = memberRoleService.selectMemberRoleList(memberRole);
        ExcelUtil<MemberRole> util = new ExcelUtil<MemberRole>(MemberRole.class);
        util.exportExcel(response, list, "用户角色数据");
    }

    /**
     * 获取用户角色详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:role:query')")
    @GetMapping(value = "/{memberId}")
    public AjaxResult getInfo(@PathVariable("memberId") Long memberId)
    {
        return success(memberRoleService.selectMemberRoleByMemberId(memberId));
    }

    /**
     * 新增用户角色
     */
    @PreAuthorize("@ss.hasPermi('system:role:add')")
    @Log(title = "用户角色", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberRole memberRole)
    {
        return toAjax(memberRoleService.insertMemberRole(memberRole));
    }

    /**
     * 修改用户角色
     */
    @PreAuthorize("@ss.hasPermi('system:role:edit')")
    @Log(title = "用户角色", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberRole memberRole)
    {
        return toAjax(memberRoleService.updateMemberRole(memberRole));
    }

    /**
     * 删除用户角色
     */
    @PreAuthorize("@ss.hasPermi('system:role:remove')")
    @Log(title = "用户角色", businessType = BusinessType.DELETE)
	@DeleteMapping("/{memberIds}")
    public AjaxResult remove(@PathVariable Long[] memberIds)
    {
        return toAjax(memberRoleService.deleteMemberRoleByMemberIds(memberIds));
    }
}
